#include "CModifyCommand.h"
#include "CUserInterface.h"
#include "CLevelEditor.h"
#include "IMeshSceneNode.h"
#include "ISceneManager.h"
#include "ISceneNode.h"
#include "CSceneObject.h"

extern CGlobals* g;
extern CUserInterface* ui;
extern CLevelEditor* editor;

CModifyCommand::CModifyCommand (int id, vector3df oldSize, vector3df newSize)
{
	m_id = id;
	m_oldSize = oldSize;
	m_newSize = newSize;
	stringw name = editor->getSceneObjectFromID(id)->m_UserData->getAttributeAsStringW("Name");
	setDescription(stringw(L"modify ") + name + L"(" + stringw(id) + L")");
}

void CModifyCommand::redo ()
{
	ISceneNode* node = g->sceneManager->getSceneNodeFromId(m_id);
	editor->updateMeshWithSize( ((IMeshSceneNode*)node)->getMesh() , m_newSize );	
	editor->getSceneObjectFromID(m_id)->m_UserData->setAttribute("Sizes" , m_newSize); 
}

void CModifyCommand::undo ()
{
	ISceneNode* node = g->sceneManager->getSceneNodeFromId(m_id);
	editor->updateMeshWithSize( ((IMeshSceneNode*)node)->getMesh() , m_oldSize );
	editor->getSceneObjectFromID(m_id)->m_UserData->setAttribute("Sizes" , m_oldSize);
}
